package com.engine4cloud.tdf.education.convert;

import com.engine4cloud.tdf.education.dto.result.EduCourseGroupResultDTO;
import com.engine4cloud.tdf.education.entity.EduCourseGroupEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;


@Mapper
public interface EduCourseGroupConvert {
    EduCourseGroupConvert INSTANCE = Mappers.getMapper(EduCourseGroupConvert.class);

    EduCourseGroupEntity create(String courseCode, String groupCode, Long tenantId);

    EduCourseGroupResultDTO convert(EduCourseGroupEntity s);

    default List<EduCourseGroupEntity> createList(String courseCode, List<String> groupList, Long tenantId) {
        if (CollectionUtils.isEmpty(groupList)) {
            return null;
        }

        List<EduCourseGroupEntity> result = new ArrayList<>();
        groupList.forEach(g -> {
            EduCourseGroupEntity entity = create(courseCode, g, tenantId);
            result.add(entity);
        });
        return result;
    }

}
